package edu.berkeley.cs160.prog1;


import java.util.ArrayList;

import android.app.Activity;
//import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
//import android.widget.EditText;
//import android.widget.PopupWindow;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

public class RestaurantActivity extends Activity implements OnClickListener, OnEditorActionListener {
	
	private ArrayList<String> actionList = new ArrayList<String>();
	private ArrayList<String> emotionList = new ArrayList<String>();
	

	//TextView splitTotal;
	private View[] chatline = new View[17];
	int viewmode = 0;
	//View partner1 = findViewById(R.id.PartnerHeadImage);
    //View partner2 = findViewById(R.id.PartnerHeadImage2);
    //View partner3 = findViewById(R.id.PartnerHeadImage3);
    //View player1 = findViewById(R.id.PlayerPortrait);
    //View player2 = findViewById(R.id.PlayerPortrait2);
    //View player3 = findViewById(R.id.PlayerPortrait3);
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.restaurant_view);
        chatline[0] = findViewById(R.id.ChatLine1);
        chatline[1] = findViewById(R.id.ChatLine2);
        chatline[2] = findViewById(R.id.ChatLine3);
        chatline[3] = findViewById(R.id.ChatLine4);
        chatline[4] = findViewById(R.id.ChatLine5);
        chatline[5] = findViewById(R.id.ChatLine6);
        chatline[6] = findViewById(R.id.ChatLine7);
        chatline[7] = findViewById(R.id.ChatLine8);
        chatline[8] = findViewById(R.id.ChatLine9);
        chatline[9] = findViewById(R.id.ChatLine10);
        chatline[10] = findViewById(R.id.ChatLine11);
        chatline[11] = findViewById(R.id.ChatLine12);
        chatline[12] = findViewById(R.id.ChatLine13);
        chatline[13] = findViewById(R.id.ChatLine14);
        chatline[14] = findViewById(R.id.ChatLine15);
        chatline[15] = findViewById(R.id.ChatLine16);
        chatline[16] = findViewById(R.id.ChatLine17);
        
        
        for (int i=0;i<17;i++) {
        	chatline[i].setVisibility(View.GONE);
        }
        
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
			public void run() {
				chatline[viewmode].setVisibility(View.VISIBLE);
				viewmode++;
			}        	
        }, 2000);
        Button sendButton = (Button) findViewById(R.id.SendButton);
        sendButton.setOnClickListener(cReveal);
        
        //PopupWindow pw = new PopupWindow(findViewById(R.layout.aeselect_view),384,384,true);
        /*Intent myIntent = new Intent(this, Select.class);		//create a new activity!!@@@@@
        Bundle action = new Bundle();
        action.putStringArrayList("actions", actionList);
        action.putStringArrayList("emotions", emotionList);
        myIntent.putExtras(action);
        this.startActivity(myIntent);		//start a different activity!!!!!!@@@@@ */
    }
    

    OnClickListener cReveal = new OnClickListener() {
    	Handler handler = new Handler();
    	public void onClick (View v) {
    		if (viewmode==1) {
    			chatline[viewmode].setVisibility(View.VISIBLE);
    			viewmode++;
    			chatline[viewmode].setVisibility(View.VISIBLE);
    			viewmode++;
    	        handler.postDelayed(new Runnable() {
    				public void run() {
    					chatline[viewmode++].setVisibility(View.VISIBLE);
    				}        	
    	        }, 5000);
    	        //partner2.setVisibility(View.INVISIBLE);
    	        //partner1.setVisibility(View.VISIBLE);
    	        findViewById(R.id.PlayerPortrait2).setVisibility(View.INVISIBLE);
    	        findViewById(R.id.PlayerPortrait3).setVisibility(View.VISIBLE);
    		} else if (viewmode==4) {
    			chatline[viewmode-4].setVisibility(View.GONE);
    			chatline[viewmode++].setVisibility(View.VISIBLE);
    			handler.postDelayed(new Runnable() {
     				public void run() {
     					chatline[viewmode-4].setVisibility(View.GONE);
     					chatline[viewmode++].setVisibility(View.VISIBLE);
     				}        	
     	        }, 1000);
    			handler.postDelayed(new Runnable() {
    				public void run() {
    					chatline[viewmode-4].setVisibility(View.GONE);
    					chatline[viewmode++].setVisibility(View.VISIBLE);
    					chatline[viewmode-4].setVisibility(View.GONE);
    					chatline[viewmode++].setVisibility(View.VISIBLE);
    				}        	
    	        }, 2000);
    	        findViewById(R.id.PartnerHeadImage2).setVisibility(View.INVISIBLE);
    	        handler.postDelayed(new Runnable() {
    				public void run() {
    					chatline[viewmode-4].setVisibility(View.GONE);
    					chatline[viewmode++].setVisibility(View.VISIBLE);
    					chatline[viewmode-4].setVisibility(View.GONE);
    					chatline[viewmode++].setVisibility(View.VISIBLE);
    				}        	
    	        }, 5000);

    	        findViewById(R.id.PartnerHeadImage3).setVisibility(View.VISIBLE);
    		} else if (viewmode==10) {
    			chatline[viewmode-4].setVisibility(View.GONE);
    			chatline[viewmode++].setVisibility(View.VISIBLE);
    			handler.postDelayed(new Runnable() {
    				public void run() {
    					chatline[viewmode-4].setVisibility(View.GONE);
    					chatline[viewmode++].setVisibility(View.VISIBLE);
    				}        	
    	        }, 1000);
    	        findViewById(R.id.PlayerPortrait3).setVisibility(View.INVISIBLE);
    	        findViewById(R.id.PlayerPortrait).setVisibility(View.VISIBLE);
    		} else if (viewmode==12) {
    			chatline[viewmode-4].setVisibility(View.GONE);
    			chatline[viewmode++].setVisibility(View.VISIBLE);
    			handler.postDelayed(new Runnable() {
    				public void run() {
    					chatline[viewmode-4].setVisibility(View.GONE);
    					chatline[viewmode++].setVisibility(View.VISIBLE);
    				}        	
    	        }, 1000);
       	        findViewById(R.id.PartnerHeadImage3).setVisibility(View.INVISIBLE);
    	        findViewById(R.id.PartnerHeadImage).setVisibility(View.VISIBLE);
    			handler.postDelayed(new Runnable() {
    				public void run() {
    					chatline[viewmode-4].setVisibility(View.GONE);
    					chatline[viewmode++].setVisibility(View.VISIBLE);
    					chatline[viewmode-4].setVisibility(View.GONE);
    					chatline[viewmode++].setVisibility(View.VISIBLE);
    				}        	
    	        }, 5000);
    	        findViewById(R.id.PlayerPortrait).setVisibility(View.INVISIBLE);
    	        findViewById(R.id.PlayerPortrait3).setVisibility(View.VISIBLE);
       	        findViewById(R.id.PartnerHeadImage).setVisibility(View.INVISIBLE);
    	        findViewById(R.id.PartnerHeadImage2).setVisibility(View.VISIBLE);
    		} else if (viewmode==16) {
    			findViewById(R.id.PartnerHeadImage2).setVisibility(View.INVISIBLE);
    	        findViewById(R.id.PartnerHeadImage3).setVisibility(View.VISIBLE);
    			chatline[viewmode-4].setVisibility(View.GONE);
    			chatline[viewmode++].setVisibility(View.VISIBLE);
    			
    		}
    		
    		else if (viewmode==17){
    			finish();
    		}
    	}
    };
    
    public void onClick (View v) {
    	
    	this.finish();
    }


	public boolean onEditorAction(TextView splitEditor, int actionId, KeyEvent event) {
		return true;

	}



	public ArrayList<String> getActionList() {
		return actionList;
	}



	public void setActionList(ArrayList<String> actionList) {
		actionList.add("Do Nothing");
		actionList.add("Smile");
		actionList.add("Frown");
		actionList.add("Wave");
		this.actionList = actionList;
	}



	public ArrayList<String> getEmotionList() {
		return emotionList;
	}



	public void setEmotionList(ArrayList<String> emotionList) {
		emotionList.add("Happy");
		emotionList.add("Angry");
		emotionList.add("Sad");
		emotionList.add("Calm");
		this.emotionList = emotionList;
	}
    
}